Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.default = void 0;

var _config = _interopRequireDefault(require("./config")), _promise = _interopRequireDefault(require("../public/utils/promise")), _diff = _interopRequireDefault(require("../public/utils/diff")), _util2 = _interopRequireDefault(require("../public/utils/util"));

function _interopRequireDefault(e) {
    return e && e.__esModule ? e : {
        default: e
    };
}

function deepCopy(e) {
    return JSON.parse(JSON.stringify(e));
}

function isLocalFile() {
    var e = 0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : "";
    return e = (e ? String(e) : "").trim(), /^wxfile/.test(e) || /^http:\/\/tmp/.test(e) || /^http:\/\/wxfile/.test(e);
}

function dowload(e) {
    return e = e.replace("http:", "https:"), wx.fPromise("downloadFile", {
        url: e
    }).catch(function() {
        return wx.showModal({
            content: "下载失败，请重新尝试",
            showCancel: !1
        }), Promise.reject();
    });
}

function writePhotosAlbum(i) {
    return new _promise.default(function(e, t) {
        wx.facility("saveImageToPhotosAlbum", {
            filePath: i.tempFilePath,
            success: e,
            fail: t
        });
    });
}

function savePhotoToAlbum(e) {
    wx.showLoading({
        mask: !0
    });
    var t = (isLocalFile(e) ? Promise.resolve({
        tempFilePath: e
    }) : dowload(e)).then(function(e) {
        return writePhotosAlbum(e);
    });
    return t.then(wx.hideLoading, wx.hideLoading), t;
}

function isLetter(e) {
    return e <= 90 && 65 <= e;
}

function sortByLetterKey(e) {
    return e.sort(function(e, t) {
        var i = e.charCodeAt(0), r = t.charCodeAt(0);
        return isLetter(i) && isLetter(r) ? t < e ? 1 : -1 : isLetter(i) || isLetter(r) || "#" === e || "#" === t ? e < t ? 1 : -1 : e < t ? -1 : 1;
    }), e;
}

function concatListToData(o) {
    var e = 1 < arguments.length && void 0 !== arguments[1] ? arguments[1] : {}, t = e.groupedKeys, n = void 0 === t ? [] : t, i = e.groupedList, a = void 0 === i ? {} : i, c = 2 < arguments.length ? arguments[2] : void 0, s = n.length, u = {};
    return o.groupedKeys.forEach(function(i, e) {
        n.includes(i) || (u["groupedKeys[".concat(s + e, "]")] = i);
        var t = o.groupedList[i];
        c && (t = stickLeader(t));
        var r = a[i];
        r ? t.forEach(function(e, t) {
            u["groupedList.".concat(i, "[").concat(r.length + t, "]")] = e;
        }) : u["groupedList.".concat(i)] = t;
    }), u;
}

function stickLeader(e) {
    if (e.length < 2) return e;
    var t = [], i = [];
    return e.forEach(function(e) {
        if (2 == +e.grade) return t.push(e);
        i.push(e);
    }), e = sortMemberList(e), t.concat(i);
}

function sortMemberList(e) {
    if (e.length <= 1) return e;
    var t = Math.floor(e.length / 2), i = e.splice(t, 1)[0], r = [], o = [], n = !0, a = !1, c = void 0;
    try {
        for (var s, u = e[Symbol.iterator](); !(n = (s = u.next()).done); n = !0) {
            var l = s.value;
            l.membersort <= i.membersort ? r.push(l) : o.push(l);
        }
    } catch (e) {
        a = !0, c = e;
    } finally {
        try {
            n || null == u.return || u.return();
        } finally {
            if (a) throw c;
        }
    }
    return sortMemberList(o).concat([ i ], sortMemberList(r));
}

var BASE_DEVICE_WIDTH = 750, _wx$getSystemInfoSync = wx.getSystemInfoSync(), windowWidth = _wx$getSystemInfoSync.windowWidth, calcRpx = function(e) {
    return e * (windowWidth / BASE_DEVICE_WIDTH);
}, calcPx = function(e) {
    return e * (BASE_DEVICE_WIDTH / windowWidth);
};

function regExpSeparateLabels(e, t) {
    var o = [], r = "$$__qunyingyong__$$";
    return e.replace(t, function(e, t, i) {
        return o.push({
            style: t,
            content: i
        }), r;
    }).split(r).reduce(function(e, t, i) {
        var r = [ {
            content: t
        } ];
        return o[i] && r.push(o[i]), e.concat(r);
    }, []);
}

function getSiteModelPUrl(e) {
    var t = e.sid, i = e.modid, r = e.navid, o = e.catid, n = e.cid, a = {
        sid: t,
        modid: i,
        navid: r,
        catid: o
    };
    if (a = 4 == +i ? Object.assign(a, {
        model: "services_project",
        id: n,
        op: "link"
    }) : 5 == +i ? Object.assign(a, {
        caseid: n,
        cid: n
    }) : Object.assign(a, {
        cid: n
    }), !_util2.default.isEmptyObject(a) && void 0 !== a.modid) {
        if (4 != +a.modid) a = Object.assign(a, {
            op: a.cid ? "link" : "view"
        }); else {
            var c = a.cid || a.id;
            delete (a = Object.assign(a, {
                op: c ? "link" : "view",
                id: c
            })).cid;
        }
        return createModelUrl(_config.default.model, a) + "&source=".concat(_config.default.WX_APP_NAME);
    }
}

function createModelUrl(e, t) {
    var i, r, o = e, n = "";
    if (1 == +t.id) return "/miniweb/pages/website/index/index?sid=".concat(t.sid);
    var a = o.find(function(e) {
        return +e.modid == +t.modid;
    });
    if (i = a ? a.modtemplate : "", n = Object.keys(t).map(function(e) {
        return e + "=" + t[e];
    }).join("&"), 1 == +t.modid) r = i; else if (4 == +t.modid) if ("link" === t.op) {
        var c = "services_project" === t.model ? "project" : "user";
        r = "".concat(c, "/view/view");
    } else r = "list/list"; else r = "link" === t.op ? "view/view" : "list/list";
    return "/miniweb/pages/model/".concat(i, "/").concat(r, "?").concat(n);
}

function checkIsToChat(e) {
    var t = getCurrentPages(), i = t[t.length - 2] || {}, r = "publicPackage/salesradar/minichat/minichat" === i.route;
    return r && (e.chatid = i.data.chatid, i.resetNum = 0, i.$emit("minichat.page.reset", e), 
    i.$route("back")), r;
}

var _default = {
    deepCopy: deepCopy,
    isLocalFile: isLocalFile,
    dowload: dowload,
    writePhotosAlbum: writePhotosAlbum,
    savePhotoToAlbum: savePhotoToAlbum,
    sortByLetterKey: sortByLetterKey,
    concatListToData: concatListToData,
    isLetter: isLetter,
    calcRpx: calcRpx,
    calcPx: calcPx,
    regExpSeparateLabels: regExpSeparateLabels,
    diff: _diff.default,
    createModelUrl: createModelUrl,
    getSiteModelPUrl: getSiteModelPUrl,
    checkIsToChat: checkIsToChat
};

exports.default = _default;